<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue/vue.js"></script>
    <script src="../../js/jquery/jquery.js"></script>
</head>
<body>
    <a href="add.html">添加</a>
    <div id="app">
        <ul>
            <li v-for="item in emps">
                {{item.id}}-{{item.name}}-{{item.age}}
                <a v-bind:href="'edit.html?id=' + item.id ">编辑</a>
                <a href="#" v-on:click="_delete(item.id)">删除</a>
            </li>
        </ul>
    </div>
    <script>
        var vue = new Vue({
            el : "#app",
            data: {
                emps:[]
            },
            methods : {
                _delete:function(id) {
                    console.log(id);
                    $.ajax({
                        url : "http://127.0.0.1:8080/employees/delete",
                        type : "DELETE",
                        data: {id:id},
                        success : function(data) {
                            if (data.code == 200) {
                                window.location.href = "list.html";
                            }else {
                                alert("操作失败");
                            }
                        }
                    })
                }
            },
            mounted:function() {
                var _this = this;
                // 跨域访问，注意被访问服务器需要设置允许访问
                $.get('http://127.0.0.1:8080/employees/list', function(data) {
                    console.log(data);
                    _this.emps = data;
                })
            }
        });


    </script>
</body>
</html>